package com.example.anew.journey.mynewjourney.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 杭州惟君医疗科技有限公司14
 * Created by 20433 on 2018/3/20
 */

public class MyYShaftCustomView extends View {

    private int YoffSet = 60;  //y轴的偏移量
    private int mColor = 0xff323232;  //轴画笔的颜色
    private Paint mpaint;
    private int YShaftwidth; //控件宽
    private int YShaftheight; //控件高
    private String[] arr = new String[]{"100","120","140","160","180"};
    private int HeightPerScale;

    public MyYShaftCustomView(Context context) {
        this(context,null);
    }

    public MyYShaftCustomView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public MyYShaftCustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        init();
    }

    private void init() {
        mpaint = new Paint();
        mpaint.setAntiAlias(true);
        mpaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mpaint.setColor(mColor);
        mpaint.setTextSize(25);
        mpaint.setStrokeWidth(1);
    }
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        YShaftwidth = w;
        YShaftheight = h;
        HeightPerScale = (YShaftheight-(2*YoffSet))/4;
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // todo 绘制文本
        drawCalibration(canvas);

    }

    private void drawCalibration(Canvas canvas) {
        for (int i = 0; i < arr.length; i++) {
            canvas.drawText(arr[i],YShaftwidth/3,YShaftheight-(YoffSet+HeightPerScale*i)-10,mpaint);
        }

    }
}
